package guowenlong.golf.ui.friend.myfriends;

import java.util.Comparator;
import me.wenlong.mixutils.util.LogUtils;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;

public class LetterComparator implements Comparator<ContactsInfo> {

  @Override
  public int compare(ContactsInfo l, ContactsInfo r) {
    if (l == null || r == null) {
      return 0;
    }
    String lhsSortLetters = HanyuPinyinHelper.getFirstLetters(l.getName().substring(0, 1),
        HanyuPinyinCaseType.UPPERCASE);
    String rhsSortLetters = HanyuPinyinHelper
        .getFirstLetters(r.getName().substring(0, 1), HanyuPinyinCaseType.UPPERCASE);
    LogUtils.e(lhsSortLetters + "   " + rhsSortLetters);
    if (lhsSortLetters == null || rhsSortLetters == null) {
      return 0;
    }
    return lhsSortLetters.compareTo(rhsSortLetters);
  }
}